package com.lkm.app_ui.m.Imple.initapp;

import com.lkm.app_ui.AppConfig;
import com.lkm.app_ui.AppConst;
import com.lkm.app_ui.help.RootCommand;
import com.lkm.comlib.task2.DefaultTaskExecutor;
import com.lkm.frame.file.FileHelper;
import com.lkm.frame.task2.Task;
import com.lkm.frame.task2.TaskAdapter;
import com.lkm.javatool.StringHelp;
import com.ta.utdid2.device.UTDevice;

import java.io.File;



@Deprecated
class InitAppConstTask extends TaskAdapter<Void, Void, String> {

    public static void ex(InitPreTask preTask) {
        Task task = new InitAppConstTask();
        preTask.addBefore(task);
        task.action();
        task.execTask();
    }

    private InitAppConstTask() {
        super(new DefaultTaskExecutor(AppConst.getTaskExecutor(), true), InitAppConstTask.class.getName(), AppConst.getTaskManager2());
    }

    @Override
    public boolean onInterceptFinish(Task<Void, ?, String> task, String result) {
        synchronized (AppConst.class) {
            AppConst.deviceUncode = result;
        }
        return super.onInterceptFinish(task, result);
    }
    @Override
    public void doExecuting(Void param) {
        super.doExecuting(param);

        mTaskExecutor.executor(new Runnable() {
            @Override
            public void run() {
                RootCommand.run ("chmod 777 " + AppConst.getApplication().getPackageCodePath());

                AppConfig.DataFile.init();

                File file = new File(AppConfig.DataFile.getDeviceUncodePath());
                String deviceUncode = FileHelper.getString(file, AppConst.charset);

                if (StringHelp.isEmpty(deviceUncode)) {
                    deviceUncode = UTDevice.getUtdid(AppConst.getApplication());
                    FileHelper.SaveString(deviceUncode, file, AppConst.charset, true);
                }
                complete(deviceUncode);
            }
        });
    }
}
